/**
 * Created by wyy on 17-7-6.
 */
angular.module('tribalc').controller('IndexController',['$rootScope', '$scope', '$state','Api','Alert',
      function ($rootScope, $scope, $state,Api,Alert) {
    function login() {
        var username = $scope.username;
        var password = $scope.password;

        $rootScope.alerttex = null;
        $rootScope.succState = false;

        // console.log(username);
        // console.log(password);

        if (!username || !password) {
                return Alert.alertBox('账号或密码不能为空');

            }
        Api.login(username, password, function (response) {
                // console.log(response);
                localStorage.assign = response.data.assigned;
                localStorage.token = response.data.token;
                $state.go('company.companyApartmentManage');
            })


    }

           $scope.clicklogin = login
        gotoDefaultPage();
        function gotoDefaultPage() {

            if (!Api.getAssign()) {
                return false;
            }
            $state.go('company');

        }
      }
]);